// 引入获取商品的请求
import * as api from "&/api"
export default{
    namespaced: true,
    state: {
        productData:[]
    },
    mutations: {
        // 要更改productData的mutation
        SET_PRODUCT_DATA(state,payload){
            state.productData =payload
        },
        DECREASE_INVENTORY(state,payload){
            // payloadd接收的是库存减少这条数据的id
            console.log(payload);
            let target = state.productData.find(item =>item.id===payload)

            if(target){
                target.inventory--
            }
        }
    },
    actions: {
        //action获取异步数据
      async  FETCH_PRODUCT(context){
            let res =await api.fetchProduct();
            console.log(res);
            context.commit('SET_PRODUCT_DATA',res.data)

        }
    },
    getters: {
        
    },
}